<div class="main layui-clear">
    <div class="wrap">
        <div class="content detail">
            <div class="fly-panel detail-box">
                <h1>
                    <?php echo $question['title'] ?>
                </h1>
                <div class="fly-tip fly-detail-hint">
                <?php if ($question['status']=='未结贴') { ?>
                    <span>
                        <?php echo $question['status'] ?>
                    </span>
                <?php }else{ ?>
                     <span style="background:#8FCDA0">
                        <?php echo $question['status'] ?>
                    </span>
                 <?php } ?>
                    <div class="jie-admin-box" data-id="8815">
                    </div>
                    <div class="fly-list-hint">
                        <a href="#comment">
                            <i class="iconfont" title="回答">
                                
                            </i>
                            <?php echo $question['answer_num'] ?>
                        </a>
                        <i class="iconfont" title="人气">
                            
                        </i>
                        <?php echo $question['view_num'] ?>
                    </div>
                </div>
                <div class="detail-about">
                    <a class="jie-user" href="{:U('home/use/index',array('id'=>$question['uid']))}">
                        <img src="__ROOT__/<?php echo $question['face'] ?>" alt="<?php echo $question['nickname'] ?>">
                        <cite>
                            <?php echo $question['nickname'] ?>
                            <em>
                            <?php echo CT($question['create_time']) ?>
                            </em>
                        </cite>
                    </a>
                    <div class="detail-hits" id="LAY_jieAdmin" data-id="8815">
                        <span style="color:#FF7200">
                            悬赏：<?php echo $question['kiss_num'] ?> 飞吻
                        </span>

                        <?php if ($use) { ?>
                            <span class="layui-btn layui-btn-mini jie-admin layui-btn-danger collect" type="collect" data-type="add" questionid="<?php echo $question['id'] ?>">
                                取消收藏
                            </span>
                        <?php }else{ ?>
                            <span class="layui-btn layui-btn-mini jie-admin collect" type="collect" data-type="add" questionid="<?php echo $question['id'] ?>">
                                收藏
                            </span>
                         <?php } ?>

                    </div>
                </div>
                <div class="detail-body photos">
                    <?php echo htmlspecialchars_decode($question['content']) ?>
                </div>
            </div>
            
            <div class="fly-panel detail-box" style="padding-top: 0;">
                <ul class="jieda photos" id="jieda">

                    <?php if (empty($answer)) { ?>
                       <li class="fly-none">
                            没有任何回答
                        </li>
                    <?php }else{ ?>
                        <?php foreach ($answer as $v) { ?>
                        <li data-id="30242">
                            <a name="item-1490922953351">
                            </a>
                            <div class="detail-about detail-about-reply">
                                <a class="jie-user" href="{:U('home/use/index',array('id'=>$v['uid']))}">
                                    <img src="__ROOT__/<?php echo $v['face'] ?>" alt="" layer-index="0">
                                    <cite>
                                        <i>
                                            <?php echo $v['nickname'] ?>
                                        </i>
                                        <em style="padding:0 ; color: #FF7200;">
                                            VIP2
                                        </em>
                                    </cite>
                                </a>
                                <div class="detail-hits">
                                    <span>
                                        <?php echo CT($v['create_time']) ?>
                                    </span>
                                </div>
                                <?php if ($v['status']=='1' and $question['status']=='已采纳') { ?>
                                     <i class="iconfont icon-caina" title="最佳答案"></i>
                                <?php } ?>
                            </div>
                            <div class="detail-body jieda-body">
                                <?php echo xbs(htmlspecialchars_decode($v['content'])) ?>
                            </div>
                            <div class="jieda-reply">
                                <span class="jieda-zan " type="zan">
                                    <i class="iconfont icon-zan zan"  answerid='<?php echo $v['id'] ?>'>
                                    </i>
                                    <em><?php echo $v['zan_num'] ?></em>
                                </span>
                                <span type="reply" class="reply" nickname='<?php echo $v['nickname'] ?>'>
                                    <i class="iconfont icon-svgmoban53 " >
                                    </i>
                                    回复
                                </span>
                                <?php if ($question['status']=='未结贴' and $question['uid']==$_SESSION['id']) { ?>
                                        <div class="jieda-admin">
                                            <span class="jieda-accept accept" type="accept" acceptid="<?php echo $v['id'] ?>" questionid="<?php echo $question['id'] ?>">
                                                采纳
                                            </span>
                                        </div>
                                <?php } ?>
                            </div>
                        </li>
                   <?php } ?>
                    <?php } ?>
                    
                    
                </ul>
                <div class="layui-form layui-form-pane">
                    <form action="/jie/reply/" method="post">
                        <div id="answer"></div>
                        <input type="hidden" name="qid" value="<?php echo $question['id'] ?>">
                        <div class="layui-form-item" style="margin-top:20px;">
                            <input type="hidden" name="jid" value="8815">
                            <input type="hidden" name="daPages" value="0">
                            <button class="layui-btn" lay-filter="answer" lay-submit="">
                                提交回答
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="edge">
        <dl class="fly-panel fly-list-one">
            <dt class="fly-panel-title">
                最近热帖
            </dt>

            <?php foreach ($hotView as $row) { ?>
                <dd>
                <a href="{:U('home/question/index',array('id'=>$row['id']))}">
                    <?php echo $row['title'] ?>
                </a>
                <span>
                    <i class="iconfont">
                        
                    </i>
                    <?php echo $row['view_num'] ?>
                </span>
            </dd>
            <?php } ?>
            
        </dl>
        <dl class="fly-panel fly-list-one">
            <dt class="fly-panel-title">
                近期热议
            </dt>

            <?php foreach ($hotAnswer as $row) { ?>
                
            <dd>
                <a href="{:U('home/question/index',array('id'=>$row['id']))}">
                     <?php echo $row['title'] ?>
                </a>
                <span>
                    <i class="iconfont">
                        
                    </i>
                     <?php echo $row['answer_num'] ?>
                </span>
            </dd>
            <?php } ?>
        </dl>
    </div>
</div>
 <script type="text/javascript">
            layui.use(['form','jquery','layedit'], function(){
                form = layui.form();
                layer = layui.layer;
                $ = layui.jquery;
                layedit = layui.layedit;

                layedit.set({
                      uploadImage: {
                        url: '{:U('home/question/answerimg')}' 
                        ,type: '' //默认post
                      }
                    });

                index = layedit.build('answer', {
                      height: 180 //设置编辑器高度
                    });

               
                //监听提交
                form.on('submit(answer)', function(data){

                    // console.log(data);

                    content = layedit.getContent(index);

                    data.field.content = content;

                    $.ajax({
                        url: '{:U('home/question/answer')}',
                        type: 'POST',
                        dataType: 'json',
                        data: data.field,
                    })
                    .done(function(reply) {
                        if (reply.error==1) {
                            layer.msg(reply.info, function(){
                            });
                        }else{  
                            layer.alert(reply.info, {icon: 6}, 
                                function  () {
                                location.replace(reply.url)
                            });
                        }
                    })
                    .fail(function() {
                        console.log("error");
                    })
                    
              
                    return false;
                });
                       $('.collect').click(function(event) {
                            qid = $(this).attr('questionid');
                           $.ajax({
                               url: '{:U('home/question/collect')}',
                               type: 'POST',
                               dataType: 'json',
                               data: {qid:qid},
                           })
                           .done(function(respond) {
                            if (respond.error==1) {
                                $('.collect').html("收藏");
                                 $('.collect').removeClass('layui-btn-danger');
                               layer.alert(respond.info, {icon: 6},
                                    function  () {
                                    location.replace(respond.url)
                            })
                            }else{ 
                                $('.collect').html("取消收藏");
                                 $('.collect').addClass('layui-btn-danger');
                                layer.alert(respond.info, {icon: 6},
                                    function  () {
                                    location.replace(respond.url)
                            })
                           }
                        })
                           .fail(function() {
                               console.log("error");
                           })                        
                       });

                        $('.zan').click(function(event) {
                            obj = $(this);

                            aid = $(this).attr('answerid');

                           $.ajax({
                               url: '{:U('home/question/addzan')}',
                               type: 'POST',
                               dataType: 'json',
                               data: {aid:aid},
                           })
                           .done(function(respond) {
                            if (respond.error==1) {
                                num = obj.siblings('em').html();
                                obj.siblings('em').html(parseInt(num)-1);
                                obj.attr("style","color:#999999");
                               layer.alert(respond.info, {icon: 6},'',
                                    function  () {
                                    location.replace()
                            })
                            }else{ 
                                num = obj.siblings('em').html();
                                 obj.siblings('em').html(parseInt(num)+1);
                                obj.attr("style","color:red");
                                layer.alert(respond.info, {icon: 6},'',
                                    function  () {
                                    location.replace()
                            })
                           }
                        })
                           .fail(function() {
                               console.log("error");
                           })                        
                       });

                        $('.reply').click(function(event) {

                            obj = $(this);

                            nickname = obj.attr('nickname');

                            str = "@"+nickname+'@';

                            content = layedit.getContent(index); 

                            if (content.indexOf(str)=='-1') {

                                str = content+str;

                                layedit.setContent(index,str);

                                layedit.xbsfocus(index);
                            };
                        });

                        $('.accept').click(function(event) {

                            obj = $(this);

                            acceptid = obj.attr('acceptid');

                            questionid = obj.attr('questionid')

                            $.ajax({
                                url: '{:U('home/question/accept')}',
                                type: 'POST',
                                dataType: 'json',
                                data: {acceptid: acceptid,questionid: questionid},
                            })
                            .done(function() {
                                    location.reload();
                            })
                            .fail(function() {
                                console.log("error");
                            })
                        
                         });
                   });
                    

        </script>